import { getAreaObj } from '@/utils/util'
import { getStore } from '@/utils/store'
const userInfo = getStore('userInfo') || {}
let creditCode = userInfo.organizationId || ''
creditCode = creditCode == 1 ? undefined : creditCode

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '设备信息',
			span: 24,
		},
		{
			label: '维护时间',
			prop: 'maintainTime',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 24,
			rules: [{ required: true, message: '请选择维护时间' }],
		},
		{
			label: '维护人',
			prop: 'maintainUserId',
			propName: 'maintainUser',
			type: 'autoSelect',
			api: 'getSecurityUserPage',
			filterKey: 'userId',
			filterLabel: 'realName',
			paramsObj: {
				// roleName: '安全员',
				classifyId: 4,
			},
			span: 24,
			rules: [{ required: true, message: '请输入维护人' }],
		},

		{
			label: '维护状态',
			prop: 'maintainState',
			type: 'select',
			dicData: [
				{ label: '正常', value: 0 },
				{ label: '异常', value: 1 },
				{ label: '已解决', value: 2 },
			],
			span: 24,
			rules: [{ required: true, message: '请选择维护状态' }],
		},
		{
			label: '备注',
			prop: 'description',
			type: 'input',
			span: 24,
		},
		{
			label: '维护图片',
			prop: 'maintainPicture',
			type: 'upload',
			span: 24,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '设备编号', prop: 'equipmentNo' },
		{ label: '设备名称', prop: 'equipmentName' },
		{ label: '维护时间', prop: 'maintainTime' },
		{
			label: '维护状态',
			prop: 'maintainState',
			custome: 'tag',
			dicData: [
				{ label: '正常', value: 0, type: 'success' },
				{ label: '异常', value: 1, type: 'danger' },
				{ label: '已解决', value: 2, type: 'info' },
			],
		},
		{
			label: '操作',
			prop: 'menu',
			width: 100,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_dotEquipmentMaintainRecord_page',
}
export const baseConfig = {
	pageName: '智能设备维护管理',
	dictcodes: ['EQUIPMENT_TYPE'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'maintainTime',
	exportMqTopic: '/ning/export/',
	api,
	auth: {
		...api,
	},
	paramsObj: {
		source: 1,
	},
	menuBtn: [
		{
			icon: 'detail',
			label: '查看',
			type: 'primary',
			operate: 'detail',
			auth: api.index,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '55%',
	},
	formConfig,
	tableConfig,
	detailConfig: formConfig,
	beforeOnLoadFormate: async (params) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(params.areas)
			resolve({
				...params,
				...areaObj,
				areas: undefined,
			})
		})
	},
}
